<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    Array.prototype.Mymap = function (fn) {
        let result = [];
        if (typeof fn === 'function') {
            for (let i = 0; i < this.length; i++) {
                let mapValue = fn.call(this, this[i], i, this);
                result.push(mapValue);
            }
            return result;
        }
        else
        {
            throw  new Error("请输入函数作为map方法");
        }
    }

    let arr = [1, 2, 3];
    let newMap = arr.Mymap((item, index, arr) => {
        return item * item;
    })
    console.log(newMap);

</script>

<body>

</body>

</html>